from django.db import models
from django.contrib.auth.models import AbstractUser


class User(AbstractUser):
    """
    自定义用户模型
    继承 Django 内置的 AbstractUser，添加额外字段
    """
    avatar = models.ImageField(
        upload_to='avatars/',
        null=True,
        blank=True,
        verbose_name='头像',
        db_comment='用户头像 URL'
    )
    bio = models.TextField(
        max_length=500,
        blank=True,
        verbose_name='个人简介',
        db_comment='用户个人简介'
    )
    phone = models.CharField(
        max_length=11,
        blank=True,
        verbose_name='手机号',
        db_comment='用户手机号'
    )
    created_at = models.DateTimeField(
        auto_now_add=True,
        verbose_name='注册时间',
        db_comment='用户注册时间'
    )
    updated_at = models.DateTimeField(
        auto_now=True,
        verbose_name='更新时间',
        db_comment='信息更新时间'
    )
    
    class Meta:
        db_table = 'creation_users'
        db_table_comment = '用户表'
        verbose_name = '用户'
        verbose_name_plural = '用户管理'
        ordering = ['-created_at']
    
    def __str__(self):
        return self.username
